﻿using System;
using System.IO;
using YArchitech.LIB;
using YJKCodeBase.XmlUtility;

namespace VerticalMenu.Utility
{
	public class StateController
	{
		public static void SaveState(StateController.StateEnum state)
		{
			string workingLocation = Product.WorkingLocation;
			string xmlPath = Path.Combine(workingLocation, "StateController.xml");
			YJKCodeBase.XmlUtility.XmlHelper xmlHelper = new YJKCodeBase.XmlUtility.XmlHelper(workingLocation, "Root");
			xmlHelper.SelectNode("Root\\Datas");
			xmlHelper.SetValue("state", state.ToString());
			xmlHelper.SaveXml(xmlPath);
		}

		public static StateController.StateEnum GetState()
		{
			string workingLocation = Product.WorkingLocation;
			string text = Path.Combine(workingLocation, "StateController.xml");
			StateController.StateEnum result;
			if (!File.Exists(text))
			{
				result = StateController.StateEnum.SE_Uninit_Hide;
			}
			else
			{
				YJKCodeBase.XmlUtility.XmlHelper xmlHelper = new YJKCodeBase.XmlUtility.XmlHelper(text, "Root");
				xmlHelper.SelectNode("Root\\Datas");
				string value = xmlHelper.GetValue("state");
				if (value == string.Empty || value.CompareTo(StateController.StateEnum.SE_Uninit_Show.ToString()) == 0)
				{
					result = StateController.StateEnum.SE_Uninit_Show;
				}
				else if (value == string.Empty || value.CompareTo(StateController.StateEnum.SE_Uninit_Hide.ToString()) == 0)
				{
					result = StateController.StateEnum.SE_Uninit_Hide;
				}
				else if (value.CompareTo(StateController.StateEnum.SE_Hide.ToString()) == 0)
				{
					result = StateController.StateEnum.SE_Hide;
				}
				else
				{
					result = StateController.StateEnum.SE_Show;
				}
			}
			return result;
		}

		public enum StateEnum
		{
			SE_Uninit_Show,
			SE_Uninit_Hide,
			SE_Hide,
			SE_Show
		}
	}
}
